package com.weiaibenpao.demo.chislim.presenter;

import com.weiaibenpao.demo.chislim.base.BasePresenter;
import com.weiaibenpao.demo.chislim.bean.UserBean;
import com.weiaibenpao.demo.chislim.retrofit.RetrofitUtils;
import com.weiaibenpao.demo.chislim.retrofit.rx.LoadingTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.NetWorkTransformer;
import com.weiaibenpao.demo.chislim.retrofit.rx.SimpleObserver;
import com.weiaibenpao.demo.chislim.view.ChangePhoneView;

/**
 * Created by wlx on 2018/1/16.
 */

public class ChangePhonePresenter extends BasePresenter<ChangePhoneView> {
    public void getSeedCode(String userPhone) {
        RetrofitUtils.getAPIService().seedCode(userPhone).
                compose(new NetWorkTransformer()).
                compose(new LoadingTransformer(mContext)).
                subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(Object object) {
                        getView().seedSuccess("发送成功");
                    }

                });
    }

    /**
     *  @Query("userPhone") int userPhone,
     @Query("securityCode") int securityCode
     * @param userPhone
     */
    public void changePhone(int userId,String userPhone,String securityCode) {
        RetrofitUtils.getAPIService().postUpDatePhone(userId,userPhone,securityCode).
                compose(new NetWorkTransformer<UserBean>()).
                compose(new LoadingTransformer(mContext)).
                subscribe(new SimpleObserver<UserBean>(mCompositeDisposable) {
                    @Override
                    public void call(UserBean userBean) {
                        getView().upDataPhone(userBean);
                    }

                });
    }

}
